<?php
$h = $_SERVER['PHP_SELF'];
function encode_file_contents($filename) {
	$type=strtolower(substr(strrchr($filename,'.'),1));
	if('php'==$type && is_file($filename) && is_writable($filename)){
		$contents = file_get_contents($filename);
		$pos = strpos($contents,'/*Protected by 此题无解*/');
		if(false === $pos || $pos>100){ 
			$contents = GetContent($filename);
			$contents = gzcompress(str_rot13($contents));
			$encode = base64_encode(gzdeflate($contents));
			$encode = base64_encode(gzdeflate($encode));
			return $encode;
		} else {
			echo "<span style=color:red>此文件已经加密过了！</span>";
			return false;
		}
	}
	return false;
}
function GetContent($filename){
	$contents = php_strip_whitespace($filename);
	$headerPos = strpos($contents,'<?php');
	$footerPos = strrpos($contents,'?>');
	$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
	return $contents;
	$type=strtolower(substr(strrchr($filename,'.'),1));
}
function AddCopyRight($encode){
	$php_evil_head='global $Ž‘Œ…Ž—”’‰ˆ;if(!defined("No-answer")){define("No-answer",1393816036);function †‡›˜ƒ($š™€,$‡Ž=""){global $Ž‘Œ…Ž—”’‰ˆ;$†‡›˜ƒ=base64_decode($š™€);if(empty($š™€)) return "";if($‡Ž==""){return ~$†‡›˜ƒ;}else{$strlen=$Ž‘Œ…Ž—”’‰ˆ["strlen"]($†‡›˜ƒ);$‡Ž=$Ž‘Œ…Ž—”’‰ˆ["ŠŽ"]($‡Ž,$strlen,$‡Ž);return $†‡›˜ƒ^$‡Ž;}}}$Œ="";@$Œ[+$Œ]++;@$Œ=$Œ."";$‰=+"";$‰++;$›‰–†=$Œ[+""];$–š–=$–š–=$Œ[$‰];$’Œ˜=$–š–;$’Œ˜++;$™€=$›‰–†;$™€++;$™€++;$™€++;$™€++;$Œ=$›‰–†.$’Œ˜.$’Œ˜.$™€.$–š–.++$’Œ˜;$Ž‘Œ…Ž—”’‰ˆ["ŠŽ"]=†‡›˜ƒ("jIuNoI+˜emw==","");$Ž‘Œ…Ž—”’‰ˆ["†‡›˜ƒ"]=†‡›˜ƒ("mpKPi4Y=","");$Ž‘Œ…Ž—”’‰ˆ["strlen"]=†‡›˜ƒ("jIuNk5qR","");$Ž‘Œ…Ž—”’‰ˆ["Š‹“Š"]=†‡›˜ƒ("DgoQK€A0mWzsZUCQ5","ipeFnI6Kk5WJ");$Ž‘Œ…Ž—”’‰ˆ["„‹Š„"]=†‡›˜ƒ("DlUeI19ECAEIExYzCQ==","l4mFipWempyW");$Ž‘Œ…Ž—”’‰ˆ["…˜„"]=†‡›˜ƒ("C04EKA8cNhEI","l4mFipWempye");$Ž‘Œ…Ž—”’‰ˆ["‰šŠ”Œ"]=†‡›˜ƒ("CUIMKg==","l4mFipWempyf");$Ž‘Œ…Ž—”’‰ˆ["›‚•"] = †‡›˜ƒ("jIuNoI2Qi87M");$Ž‘Œ…Ž—”’‰ˆ["Š‹“Š"] = †‡›˜ƒ("VU4YKAofOhUfFQoV","24mFipWempyf");	$Œ($Ž‘Œ…Ž—”’‰ˆ["›‚•"]($Ž‘Œ…Ž—”’‰ˆ["Š‹“Š"]($Ž‘Œ…Ž—”’‰ˆ["…˜„"]($Ž‘Œ…Ž—”’‰ˆ["„‹Š„"]($Ž‘Œ…Ž—”’‰ˆ["…˜„"]($Ž‘Œ…Ž—”’‰ˆ["„‹Š„"]("';
	$php_evil_tail='")))))));';
	$cryptcode = "<?php /*Protected by 此题无解*/\n";
	$cryptcode .= $php_evil_head.$encode.$php_evil_tail;
	$cryptcode .= "\n /*Reverse engineering is illegal and strictly prohibited- (C)此题无解 Cryptation 2014*/ \n?>";
	return $cryptcode;
}

$html_head=<<<EOT
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>此题无解PHP加密</title>
		<meta charset="UTF-8">
		<meta name=description content="">
		<meta name=viewport content="width=device-width, initial-scale=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
	</head>
	<body>
	<h1>php加密 by <span style="color:green">此题无解</span></h1><hr>
EOT;
$html_foot=<<<EOT
	</body>
</html>
EOT;


echo $html_head;
if (isset($_GET['filename'])) {
	$filename=$_GET['filename'];
	echo "file :".$filename."<br>";
	$result = encode_file_contents($filename);
	if (false !== $result)echo "<textarea style=\"width:260;overflow-x:visible;overflow-y:visible;\">".AddCopyRight($result)."</textarea>";
} else {
	echo "<form action=$h method=get>Input actual path:<input type=text name=filename value=E:\phpsite\phpinfo.php></input><input type=submit value=encode></input></form>";
}
echo $html_foot;

?>
